package com.xuhuan.thread.study2.syn;

import java.util.ArrayList;

/**
 * @author huan.xu
 * @date 2021/9/29 16:29
 * @description ArrayList
 */
public class ArrayListDemo {

    public static void main(String[] args) {
        ArrayList<String> arrayList = new ArrayList<>();
        for (int i = 0; i < 3000; i++) {
            new Thread(() -> {
                synchronized (arrayList) {
                    arrayList.add(Thread.currentThread().getName());
                }
            }).start();
        }
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(arrayList.size());
    }

}
